package com.boe.common.util.freemark.base;

import lombok.*;
import com.boe.common.util.freemark.P0Error;
import com.boe.common.util.freemark.BaseMethodModelFreemarker;
import freemarker.template.TemplateModelException;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.util.List;


public class FreemarkerFieldListType extends BaseMethodModelFreemarker {
    @Override
    public Object exec(List list) throws TemplateModelException {
        var paramValue = getFreemarkerParameter(list.get(0));
        if (paramValue instanceof Field) {
            return ((Class) ((ParameterizedType) ((Field) paramValue).getGenericType()).getActualTypeArguments()[0]).getSimpleName();
        }
        throw new P0Error(paramValue);
    }
}
